﻿using ETA.IRepository;
using ETA.IService;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ETA.Service
{
    public class ProjectTypeService : IProjectTypeService
    {

        #region 属性

        private IProjectTypeRepository _IProjectTypeRepository { set; get; }

        #endregion

        #region 构造函数

        public ProjectTypeService(IProjectTypeRepository IProjectTypeRepository)
        {
            _IProjectTypeRepository = IProjectTypeRepository;
        }

        #endregion
        public QueryProjectTypeResponse QueryProjectTypeList(QueryProjectTypeRequest req)
        {
            var response = new QueryProjectTypeResponse();
            try
            {
                if (!string.IsNullOrEmpty(req.ProjectTypeId))
                {
                    response.ProjectTypeList = _IProjectTypeRepository.GetAllList(b => b.ProjectTypeId == req.ProjectTypeId);
                    response.Result.IsSuccess = true;
                }
                else
                {
                    response.ProjectTypeList = _IProjectTypeRepository.GetAllList();
                    response.Result.IsSuccess = true;
                }
            }
            catch (Exception e)
            {
                response.Result.ErrMessage = e.Message;
            }
            return response;
        }


        public CreateProjectTypeResponse CreateProjectType(CreateProjectTypeRequest req)
        {
            var res = new CreateProjectTypeResponse();
            if (req != null)
            {
                res.ProjectType = _IProjectTypeRepository.Insert(req.ProjectType);
                res.Result.IsSuccess = true;
            }
            return res;
        }
    }
}
